package cool.taomu.toolkit.rpc.thrift.server

import com.google.inject.Inject
import cool.taomu.toolkit.rpc.thrift.server.ClientInfoServerEventHandler
import java.util.Map
import org.apache.thrift.TProcessor
import org.apache.thrift.TProcessorFactory
import org.apache.thrift.server.TThreadPoolServer
import org.apache.thrift.server.TThreadPoolServer.Args
import org.eclipse.xtend.lib.annotations.Accessors
import org.slf4j.LoggerFactory

@Accessors
class TaomuThriftTThreadPoolServer {

	static val LOG = LoggerFactory.getLogger(TaomuThriftTThreadPoolServer);

	@Inject
	Map<String, Args> tHsHaArgs;

	def get(String name, TProcessor processor) {
		LOG.info("server:{}", name);
		var arg = tHsHaArgs.get(name)
		arg.processorFactory(new TProcessorFactory(processor));
		var server = new TThreadPoolServer(arg);
		server.serverEventHandler = new ClientInfoServerEventHandler();
		return server
	}

	def getFirst(TProcessor processor) {
		LOG.info("server:{}", tHsHaArgs.keySet.get(0));
		var arg = tHsHaArgs.get(tHsHaArgs.keySet.get(0))
		arg.processorFactory(new TProcessorFactory(processor));
		var server = new TThreadPoolServer(arg);
		server.serverEventHandler = new ClientInfoServerEventHandler();
		return server
	}

}
